﻿namespace SSG.Tools
{
    /// <summary>
    /// Calculations
    /// </summary>
    public static class Units
    {
        /// <summary>
        /// Feet in meters
        /// </summary>
        /// <param name="ft"></param>
        /// <returns></returns>
        public static double FeetToMeters(this int ft)
        {
            return 0.3048*ft;
        }

        /// <summary>
        /// Feet in meters
        /// </summary>
        /// <param name="ft"></param>
        /// <returns></returns>
        public static double FeetToMeters(this double ft)
        {
            return 0.3048*ft;
        }

        /// <summary>
        /// km -> NM
        /// </summary>
        /// <param name="km"></param>
        /// <returns></returns>
        public static double KilometersToNauticalMiles(this double km)
        {
            return km/1.852;
        }

        /// <summary>
        /// NM -> km
        /// </summary>
        /// <param name="nm"></param>
        /// <returns></returns>
        public static double NauticalMilesToKilometers(this double nm)
        {
            return nm*1.852;
        }

        /// <summary>
        /// Meters in feet
        /// </summary>
        /// <param name="meters"></param>
        /// <returns></returns>
        public static double MetersToFeet(this double meters)
        {
            return meters/0.3048;
        }

        /// <summary>
        /// Mega hertz
        /// </summary>
        /// <param name="frequency"></param>
        /// <returns></returns>
        public static string UnitMhz(this double frequency)
        {
            return frequency.ToString("0.000") + "MHz";
        }

        /// <summary>
        /// Kilo hertz
        /// </summary>
        /// <param name="frequency"></param>
        /// <returns></returns>
        public static string UnitKhz(this double frequency)
        {
            return frequency.ToString("0.000") + "kHz";
        }

        /// <summary>
        /// Kilo hertz
        /// </summary>
        /// <param name="degrees"></param>
        /// <returns></returns>
        public static string UnitDeg(this double degrees)
        {
            return degrees.ToString("0.0") + "°";
        }

        /// <summary>
        /// Nautical miles
        /// </summary>
        /// <param name="nm"></param>
        /// <returns></returns>
        public static string UnitNm(this double nm)
        {
            return nm.ToString("0.000") + "NM";
        }

        /// <summary>
        /// Kilometers
        /// </summary>
        /// <param name="km"></param>
        /// <returns></returns>
        public static string UnitKm(this double km)
        {
            return km.ToString("0.000") + "km";
        }

        /// <summary>
        /// Adds unit
        /// </summary>
        /// <param name="ft"></param>
        /// <returns></returns>
        public static string UnitFt(this int ft)
        {
            return ft + "ft";
        }

        /// <summary>
        /// Adds unit
        /// </summary>
        /// <param name="ft"></param>
        /// <returns></returns>
        public static string UnitFt(this double ft)
        {
            return ft.ToString("0") + "ft";
        }

        /// <summary>
        /// Meters
        /// </summary>
        /// <param name="meters"></param>
        /// <returns></returns>
        public static string UnitM(this int meters)
        {
            return meters + "m";
        }

        /// <summary>
        /// Meters
        /// </summary>
        /// <param name="meters"></param>
        /// <returns></returns>
        public static string UnitM(this double meters)
        {
            return meters.ToString("0.00") + "m";
        }

        /// <summary>
        /// Seconds with unit
        /// </summary>
        /// <param name="seconds"></param>
        /// <param name="digits"></param>
        /// <returns></returns>
        public static string UnitSeconds(this double seconds, bool digits = false)
        {
            return digits ? seconds.ToString("0.00") + "s" : seconds.ToString("0") + "s";
        }

        /// <summary>
        /// Seconds with unit
        /// </summary>
        /// <param name="seconds"></param>
        /// <returns></returns>
        public static string UnitSeconds(this int seconds)
        {
            return seconds + "s";
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="ftPerS"></param>
        /// <returns></returns>
        public static double FtPerSToFtPerMinute(this double ftPerS)
        {
            return ftPerS*60.0;
        }

        /// <summary>
        /// Climb rate per km
        /// </summary>
        /// <param name="speedKmPerHour"></param>
        /// <param name="climbFtMin"></param>
        /// <returns></returns>
        public static double ClimbRateFtPerKm(double speedKmPerHour, double climbFtMin)
        {
            double timeMinPerKm = (60/speedKmPerHour);
            return timeMinPerKm*climbFtMin;
        }
    }
}